package myapi

import (
	"net/http"
 common "jinquan.supor.com/common"
	jwt "github.com/dgrijalva/jwt-go"
	echo "github.com/labstack/echo"
	echos "jinquan.supor.com/echos"
)

func shellSort(arr []int) []int {
    increment:=len(arr)
    for {
        increment = increment / 2
        for i := 0; i < increment; i++ {
            for j := i + increment; j < len(arr); j = j + increment {
                for k := j; k > i; k = k - increment {
                    if arr[k] < arr[k-increment] {
                        arr[k], arr[k-increment] = arr[k-increment], arr[k]
                    } else {
                        break
                    }
                }
            }
        }
        if increment == 1 {
            break
        }
    }
    return arr
}

func API_CbFunc_shellSort(c echo.Context) error {
	user := c.Get("user").(*jwt.Token)
	claims := user.Claims.(*echos.JwtCustomClaims)
	name := claims.Name
	name = name
	// do something.....
	args := c.FormValue("args")
	arr := common.Str2IntArr(args)
	arrSort := common.PrintIntArr(shellSort(arr))
	return c.String(http.StatusOK, "shellSort/> "+arrSort)
}